<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>系统设置</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<%@include file="common.jsp"%>
</head>
<body style="margin-top:-10px;">
	<div style="margin-top:20px;">
		<button onclick="addBanner()" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#addBannerImgBox">新增</button>
		<button onclick="updateBannerBox()" class="btn btn-primary btn-lg">修改</button>
		<button onclick="delBanner()" class="btn btn-primary btn-lg">删除</button>
	</div>
	<div>
		<table id="bannerTable" class="text-nowrap"></table>
	</div>
	<div class="modal fade" id="addBannerImgBox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">添加首页轮播图</h4>
                <h4 class="modal-title" id="myModalLabel2">修改首页轮播图</h4>
            </div>
            <div class="modal-body">
           		 <form id="bannerForm" method='post' class="" enctype="multipart/form-data">
				  	<div class="form-group">
				  		<label for="exampleInputEmail2" style="float:left;">上传：</label>
				  		<input id="img" name="img" type="file" />
				  		<input id="id" name="id" hidden="ture"/>
				  	</div>
				</form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="addBanner" onclick="submit()">提交</button>
                <button type="button" class="btn btn-primary" id="updateBanner" onclick="updateBanner()">修改</button>
            </div>
        </div>
    </div>
	</div>
	<!-- 打开图片窗口 -->
	<div class="modal fade" id="imgBoxDiv" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">轮播图</h4>
            </div>
            <div class="modal-body">
			 	<div class="form-group">
			    	<img id="myimg" alt="" style="width:100%;" src=""/>
			  	</div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
	</div>
</body>
<script type="text/javascript">
//重载表格
$(function(){
	//加载表格
	$("#bannerTable").bootstrapTable({
		url: "${pageContext.request.contextPath}/bannerImg/findBannerImg.do",
		method: "post",
		cache: false,
		dataType: "json",
		contentType: "application/x-www-form-urlencoded",
		toolbar: "#toolbar",
		classes: "table table-hover table-striped",
		height:450,
		pagination: true,
		sidePagination: 'server',
		search: false,
		smartDisplay:false,
		sortOrder: "desc",
		searchText: "",
		showRefresh: false,
		showToggle: false,
		singleSelect: true,
		showPaginationSwitch: false,
		pageNumber: 1,
		pageSize: 5,
		pageList: [5, 10, 20, 40],
		clickToSelect: true,
		onCheck: function (row) {
		},
		queryParamsType: "undefined",
		queryParams: function (params) {
			var params = {
				pageNum: params.pageNumber,
				pageSize: params.pageSize,
				sortBy: params.sortOrder,
				bannerType:1
			}
			return params;
		},
		columns: [
			{ checkbox: true }
			,  {
				field: "id",
				title: "ID"
			}, {
				field: "bannerImg",
				title: "文件名字"
			}, {
				field: "createTime",
				title: "创建时间",
				formatter: formatTime
			}, {
				field: "updateEmp",
				title: "修改人"
			}, {
				field: "updateTime",
				title: "修改时间",
				formatter: formatTime
			}
			
		],
		responseHandler: function (data) {//onLoad前处理数据源
			return data;
		},
		onLoadSuccess: function (data) {	//成功时执行
		},
		onLoadError: function (data) {	//失败时执行
			return;
		},
		//双击行打开图片
		onDblClickRow:function(row){
			var imgUrl = "${pageContext.request.contextPath}/management/uploadImg/"+row.bannerImg;
			$('#myimg').attr("src",imgUrl);
			$('#imgBoxDiv').modal('show');
		}
	});
})
//打开新增轮播图对话框
function addBanner(){
	//模块框标题的文字显示与隐藏
	$('#myModalLabel').css("display","block");
	$('#myModalLabel2').css("display","none");
	//操作按钮隐藏与显示
	$("#updateBanner").hide();
	$('#addBanner').show();
	//清空表单
	document.getElementById("bannerForm").reset()
}
//新增银行信息
function submit(){
	//提交表单，新增银行信息
	$('#bannerForm').attr("action","${pageContext.request.contextPath}/bannerImg/addBannerImg.do");
	$('#bannerForm').submit();
	alert('新增成功！');
}
//打开修改轮播图对话框
function updateBannerBox(){
	var rows = $('#bannerTable').bootstrapTable('getSelections');
	if(rows.length <= 0){
		return alert("请选择数据！");
	}
	var row = rows[0];
	//ID
	$('#id').val(row.id);
	//打开修改框
	$('#addBannerImgBox').modal('show');
	//模块框标题的文字显示与隐藏
	$('#myModalLabel').css("display","none");
	$('#myModalLabel2').css("display","block");
	//操作按钮隐藏与显示
	$('#updateBanner').show();
	$("#addBanner").hide();
}
//修改轮播图
function updateBanner(){
	if(confirm("确认修改？")){
		//from对象序列化
		//var data = $('#bankTypeForm').serialize();
		//var submitData = decodeURIComponent(data,true);
		var submitData = new FormData(document.getElementById("bannerForm"));
		$.ajax({
			url: "${pageContext.request.contextPath}/bannerImg/updateBannerImg.do",
			data: submitData,
			type: "post",
			processData: false,
			contentType:false,
			success:function(data){
				alert(data);
				//刷新表格数据
				$('#bannerTable').bootstrapTable('refresh');
				//隐藏模态框
				$('#addBannerImgBox').modal('hide');
			}
		})
	}
}

//删除轮播图
function delBanner(){
	var rows = $('#bannerTable').bootstrapTable('getSelections');
	if(rows.length <= 0){
		return alert("请选择数据！");
	}
	if(confirm("确认删除？")){
		//from对象序列化
		//var data = $('#bankForm').serialize();
		//var submitData = decodeURIComponent(data,true);
		var row = rows[0];
		$.ajax({
			url:"${pageContext.request.contextPath}/bannerImg/delBannerImg.do",
			data: {
				id:row.id
			},
			type:"post",
			dataType:"json",
			processData: true,
			success:function(data){
				alert(data);
				//刷新表格数据
				$('#bannerTable').bootstrapTable('refresh');
			}
		})
	}
}
</script>
</html>




